<?php

namespace app\common\model;

use think\Exception;

class CmsRole extends BaseModel
{
    //添加身份
    public function roleAdd($data){
        //过滤数据
        $data=$this->dataFilter($data);
        $isset=$this->where("rol_name","=",$data['rol_name'])->find();
        if($isset){
            return "该身份已存在";
        }
        try{
            $result=$this->insert($data);
        }catch (Exception $e){
            return "数据插入异常";
        }
        if(!$result){
            return "身份添加成功";
        }else{
            return 1;
        }
    }


    //身份编辑
    public function roleEdit($data,$rol_id){
        $data=$this->dataFilter($data);
        try{
            $result=$this->where("rol_id","=",$rol_id)->update($data);
        }catch(Exception $e){
            return "信息编辑异常";
        }
        if(!$result){
            return "信息未发生变化";
        }else{
            refreshAdminInfoInSession();
            return 1;
        }

    }

}
